﻿using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;

public class FillController : MonoBehaviour
{
    public bool gotit;
    public float coldTime;
    private bool iscolding = false;
    private float timer;
    public Image image;
    AudioSource audioSource;

    // Start is called before the first frame update
    void Start()
    {
        timer = coldTime;
        audioSource = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        if(gotit)
        {
            gotit = false;
            iscolding = true;
            audioSource.PlayOneShot(audioSource.clip);
        }
        if(iscolding)
        {
            timer -= Time.deltaTime;
            image.fillAmount = timer / coldTime;
            if (timer <= 0)
            {
                timer = coldTime ;
                iscolding = false;
                image.fillAmount = 0;
            }
        }
    }
}
